import { DEVICE_STATE } from "../workshopOperation/constant";
export const Z2_TOKEN = "1302022";
export const Z6_TOKEN = "1302058";
export const Z7_TOKEN = "1302046";
export const Z8_TOKEN = "1302041";
export const Z9_TOKEN = "1302042";
export const Z10_TOKEN = "13020078";
export const Z11_TOKEN = "1302060";
export const Z12_TOKEN = "1302031";
export const Z13_TOKEN = "13020072";
export const Z14_TOKEN = "13020074";
export const Z15_TOKEN = "13020086";
export const Z16_TOKEN = "13020088";
export const Z17_TOKEN = "13430175";
export const Z18_TOKEN = "13020092";
export const Z19_TOKEN = "13020091";
export const Z20_TOKEN = "13020097";
export const P800_TOKEN = "P800";
export const P300_TOKEN = "P300";
export const ROUTINE_CHEMICAL = ["RBC531_HX", "RBC531_CG"];
// 一个温区的炉子
export const ONE_FURNACE = [
  "1344119",
  "1344118",
  "PY110060",
  "PY110059",
  "13070227",
  "13150226",
  "1307051",
  "1307158",
  "1344008",
  "13070201",
  "1307026",
  "1307027",
  "1307030",
  "1307033",
  "1308041",
  "1308019",
  "1308022",
  "1308046",
  "1308004",
  "1308005",
  "1307044",
  "1307128",
  "1308021",
  "1310004"
];
// 两个温区的炉子
export const TWO_FURNACE = [
  "13500041",
  "1310002",
  "13500042",
  "13100011",
  "1344094",
  "1344075",
  "1344073",
  "1344120",
  "1307028",
  "13070225",
  "1308030",
  "13020083",
  "1344072",
  "1344027",
  "1308014",
  "1308028",
  "1308025"
];
export const THREE_FURNACE = ["1308032", ""];
// 真空炉
export const VACUUM_FURNACE = ["13020097", "13020073", "1302027"];
// 化学
export const CHEMICAL = [
  "1308032",
  "1308041",
  "13020083",
  "1308019",
  "1308022",
  "1308046",
  "1344072",
  "1344027",
  "1308004",
  "1308005",
  "1307044",
  "1307128",
  "1308014",
  "1308028",
  "1308025",
  "1308021",
  "1310004"
];
// 常规
export const ROUTINE = [
  "13500041",
  "1310002",
  "13500042",
  "1344119",
  "1344118",
  "13100011",
  "1344094",
  "1344075",
  "1344073",
  "1344120",
  "1307028",
  "13070225",
  "PY110060",
  "PY110059",
  "13070227",
  "13150226",
  "1307051",
  "1307158",
  "1344008",
  "13070201",
  "1308030",
  "1307026",
  "1307027",
  "1307030",
  "1307033",
  "1308032",
  "13500041",
  "1310002"
];
// 默认直接回显文字
export const TextDetail = (
  areaPosition,
  ch_Text,
  areaName,
  imgUrl,
  prefix
) => area => {
  return [areaPosition, ch_Text, area[areaName], imgUrl, prefix];
};
// 格式0为无 1为氩气 2为氮气 3为氢气

export const EventDetails = (areaPosition, ch_Text, areaName, imgUrl) => {
  return area => {
    let text = "--";
    if (area[areaName] == "1") {
      text = "氩气";
    }
    if (area[areaName] == "2") {
      text = "氮气";
    }
    if (area[areaName] == "3") {
      text = "氢气";
    }
    if (area[areaName] == "0") {
      text = "无";
    }
    return [areaPosition, ch_Text, text, imgUrl];
  };
};
// 格式化是否
export const YesNoDetails = (areaPosition, ch_Text, areaName, imgUrl) => {
  return area => {
    let text = "--";
    if (area[areaName] == "1") {
      text = "是";
    }
    if (area[areaName] == "0") {
      text = "否";
    }
    return [areaPosition, ch_Text, text, imgUrl];
  };
};
// 格式化正常,慢速
export const SpeedDetails = (areaPosition, ch_Text, areaName, imgUrl) => {
  return area => {
    let text = "--";
    if (area[areaName] == "1") {
      text = "正常";
    }
    if (area[areaName] == "0") {
      text = "慢速";
    }
    return [areaPosition, ch_Text, text, imgUrl];
  };
};
// 格式化true false
export const StatusDetail = (areaPosition, ch_Text, areaName, imgUrl) => {
  return area => {
    let text = "--";
    if (area[areaName] == "1") {
      text = "开启";
    }
    if (area[areaName] == "0") {
      text = "关闭";
    }
    return [areaPosition, ch_Text, text, imgUrl];
  };
};
// 格式化手动  0本地、1远程
export const ModelDetail = (areaPosition, ch_Text, areaName, imgUrl) => {
  return area => {
    let text = "--";
    if (area[areaName] == "0") {
      text = "本地";
    }
    if (area[areaName] == "1") {
      text = "远程";
    }
    return [areaPosition, ch_Text, text, imgUrl];
  };
};
// 设备状态单独处理
export const DeviceStatusDetail = (areaPosition, ch_Text, areaName, imgUrl) => {
  return area => {
    return [
      areaPosition,
      ch_Text,
      DEVICE_STATE.find(item => item.value == area[areaName])?.label || "--",
      imgUrl
    ];
  };
};
// 格式化时间
export const TimeDetail = (
  areaPosition,
  ch_Text,
  areaName,
  imgUrl,
  prefix
) => area => {
  // (需要什么格式后续在这里处理  area[areaName]就是实际接口返回的值)
  return [areaPosition, ch_Text, area[areaName], imgUrl, prefix];
};
// 阶段剩余时间
export const STAGE_REMAIN_TIME = {
  meter1RunStageRemainTime: TimeDetail(
    "downArea",
    "阶段剩余时间",
    "meter1RunStageRemainTime",
    require("@/assets/images/shebeiIcon/msg_7.png"),
    "分钟"
  )
};
export const PGM_RUN_TIME = {
  pgmRunTime: TimeDetail(
    "downArea",
    "程序运行时间",
    "pgmRunTime",
    require("@/assets/images/shebeiIcon/msg_7.png"),
    "分钟"
  )
};
export const RUN_PGM_NO = {
  meter1RunPgmNO: TextDetail(
    "downArea",
    "程序号",
    "meter1RunPgmNO",
    require("@/assets/images/shebeiIcon/msg_4.png")
  )
};

export const RUNPGM_NO = {
  meter1RunStageNO: TextDetail(
    "downArea",
    "阶段号",
    "meter1RunStageNO",
    require("@/assets/images/shebeiIcon/msg_5.png")
  )
};
export const CONTRO_MODE = {
  systemControlMode: ModelDetail(
    "downArea",
    "控制模式",
    "systemControlMode",
    require("@/assets/images/shebeiIcon/msg_1.png")
  )
};
// 不带pid的基础信息
export const DEFAULT_MSG_STATUS = {
  value: DeviceStatusDetail(
    "downArea",
    "设备状态",
    "value",
    require("@/assets/images/shebeiIcon/msg_2.png")
  )
};
// 所有炉子的基础信息(都会包含的)
export const DEFAULT_MSG = {
  ...DEFAULT_MSG_STATUS,
  meter1RunPidNO: TextDetail(
    "downArea",
    "PID号",
    "meter1RunPidNO",
    require("@/assets/images/shebeiIcon/msg_3.png")
  )
};
// 基础能源信息
export const ENERGY = {
  electricKw: TextDetail(
    "downArea",
    "有功功率",
    "electricKw",
    require("@/assets/images/shebeiIcon/msg_14.png"),
    "Kw"
  ),
  electricCos: TextDetail(
    "downArea",
    "功率因数",
    "electricCos",
    require("@/assets/images/shebeiIcon/msg_15.png"),
    "%"
  ),
  electricUa: TextDetail(
    "downArea",
    "相电压Ua",
    "electricUa",
    require("@/assets/images/shebeiIcon/msg_10.png"),
    "V"
  ),
  electricUb: TextDetail(
    "downArea",
    "相电压Ub",
    "electricUb",
    require("@/assets/images/shebeiIcon/msg_10.png"),
    "V"
  ),
  electricUc: TextDetail(
    "downArea",
    "相电压Uc",
    "electricUc",
    require("@/assets/images/shebeiIcon/msg_10.png"),
    "V"
  ),
  electricIa: TextDetail(
    "downArea",
    "电流IA",
    "electricIa",
    require("@/assets/images/shebeiIcon/msg_13.png"),
    "A"
  ),
  electricIb: TextDetail(
    "downArea",
    "电流IB",
    "electricIb",
    require("@/assets/images/shebeiIcon/msg_13.png"),
    "A"
  ),
  electricIc: TextDetail(
    "downArea",
    "电流IC",
    "electricIc",
    require("@/assets/images/shebeiIcon/msg_13.png"),
    "A"
  )
};
export const PV_SP = {
  meter1RealTemp: TimeDetail(
    "downArea",
    "PV",
    "meter1RealTemp",
    require("@/assets/images/shebeiIcon/msg_7.png")
  ),
  meter1ControlTemp: TimeDetail(
    "downArea",
    "SP",
    "meter1ControlTemp",
    require("@/assets/images/shebeiIcon/msg_7.png"),
    "℃"
  )
};
// 进出水公共部分
export const JIN_CHU_DEFAULT = {
  waterInTemperture: TextDetail(
    "downArea",
    "进水温度",
    "waterInTemperture",
    require("@/assets/images/shebeiIcon/msg_1.png"),
    "℃"
  ),
  waterInPressure: TextDetail(
    "downArea",
    "进水压力",
    "waterInPressure",
    require("@/assets/images/shebeiIcon/msg_1.png"),
    "kPa"
  ),
  waterInFlow: TextDetail(
    "downArea",
    "水流量",
    "waterInFlow",
    require("@/assets/images/shebeiIcon/msg_1.png"),
    "m³/h"
  ),
  waterOutTemperture: TextDetail(
    "downArea",
    "出水温度",
    "waterOutTemperture",
    require("@/assets/images/shebeiIcon/msg_1.png"),
    "℃"
  ),
  waterOutPressure: TextDetail(
    "downArea",
    "出水压力",
    "waterOutPressure",
    require("@/assets/images/shebeiIcon/msg_1.png"),
    "kPa"
  )
};
// 常规炉===>> 内容
export const MAP_DEATIL_PREHEAT = {
  // 上部分
  ...DEFAULT_MSG,
  ...CONTRO_MODE,
  ...RUN_PGM_NO,
  ...RUNPGM_NO,
  meter1RunPgmStageCount: TimeDetail(
    "downArea",
    "程序总段数",
    "meter1RunPgmStageCount",
    require("@/assets/images/shebeiIcon/msg_1.png")
  ),
  ...STAGE_REMAIN_TIME,

  ...ENERGY
};

//化学 氨气流量
export const MAP_DEATIL_CHEMISTRY_ammoniaFlow = {
  ...MAP_DEATIL_PREHEAT,
  ammoniaFlow: TextDetail(
    "downArea",
    "氨气流量",
    "ammoniaFlow",
    require("@/assets/images/shebeiIcon/msg_1.png")
  )
};
//化学 氮气流量
export const MAP_DEATIL_CHEMISTRY_nitrogenFlow = {
  ...MAP_DEATIL_PREHEAT,
  ammoniaFlow: TextDetail(
    "downArea",
    "氮气流量",
    "nitrogenFlow",
    require("@/assets/images/shebeiIcon/msg_1.png")
  )
};
// 化学炉-25 基础信息
export const MAP_DEATIL_CHEMISTRY_25 = {
  ...MAP_DEATIL_PREHEAT,
  pressure: TextDetail(
    "downArea",
    "压力",
    "pressure",
    require("@/assets/images/shebeiIcon/msg_1.png")
  ),
  flow: TextDetail(
    "downArea",
    "流量",
    "flow",
    require("@/assets/images/shebeiIcon/msg_1.png")
  )
};

// upArea表示第一个组 downArea表示第二个组/
/** 最终返回格式
 * {
 *  upArea:[],
 *  downArea:[]
 * }
 */
export const renderJson = (DatailJson, MAP_DEATIL) => {
  const data = Object.keys(MAP_DEATIL).reduce((areas, key) => {
    const [areaPosition, ch_Text, areaName, imgUrl, prefix = ""] = MAP_DEATIL[
      key
    ]?.(DatailJson);
    const val = areaName ? `${areaName}${prefix}` : "-";
    if (!areaPosition) {
      return areas;
    }
    return {
      ...areas,
      [areaPosition]: [
        ...(areas?.[areaPosition] || []),
        {
          ch_Text: ch_Text,
          areaName: val,
          imgUrl
        }
      ]
    };
  }, {});

  return data;
};

// 不同炉子的配方参数

export const CHEMICAL_FORMULA_INFO = [
  {
    label: "阶段",
    key: "stageId",
    value: "",
    stageId: ""
  },
  {
    label: "设定温度",
    key: "setTemp",
    value: "",
    type: "input",
    setTemp: ""
  },
  {
    label: "设定时间",
    key: "setTime",
    value: "",
    type: "input",
    setTime: ""
  },
  {
    label: "温度公差",
    key: "volumeTemp",
    value: "",
    type: "input",
    volumeTemp: ""
  }
];
// 真空炉 Z-16
export const VACUUM_FORMULA_INFO_Z16 = [
  {
    label: "阶段",
    key: "stageId",
    value: "",
    type: "",
    stageId: ""
  },
  {
    label: "设定温度℃",
    key: "oneExpandInfo",
    value: "",
    type: "input",
    oneExpandInfo: ""
  },
  {
    label: "设定时间",
    key: "twoExpandInfo",
    value: "",
    type: "input",
    twoExpandInfo: ""
  },
  {
    label: "关加热",
    key: "threeExpandInfo",
    value: "",
    type: "radio",
    threeExpandInfo: "",
    options: [
      {
        label: "开",
        value: "1"
      },
      {
        label: "关",
        value: "0"
      }
    ]
  },
  {
    label: "确保平台",
    key: "fourExpandInfo",
    value: "",
    type: "radio",
    fourExpandInfo: "",
    options: [
      {
        label: "是",
        value: "1"
      },
      {
        label: "否",
        value: "0"
      }
    ]
  },
  {
    label: "分开压",
    key: "fiveExpandInfo",
    value: "",
    type: "radio",
    fiveExpandInfo: "",
    options: [
      {
        label: "开",
        value: "1"
      },
      {
        label: "关",
        value: "0"
      }
    ]
  },
  {
    label: "sixExpandInfo",
    key: "sixExpandInfo",
    value: "",
    type: "radio",
    sixExpandInfo: "",
    hide: true
  },
  {
    label: "sevenExpandInfo",
    key: "sevenExpandInfo",
    value: "",
    type: "radio",
    sevenExpandInfo: "",
    hide: true
  },
  {
    label: "eightExpandInfo",
    key: "eightExpandInfo",
    value: "",
    type: "radio",
    eightExpandInfo: "",
    hide: true
  },
  {
    label: "nineExpandInfo",
    key: "nineExpandInfo",
    value: "",
    type: "radio",
    eightExpandInfo: "",
    hide: true
  },
  {
    label: "tenExpandInfo",
    key: "tenExpandInfo",
    value: "",
    type: "radio",
    eightExpandInfo: "",
    hide: true
  }
];
// 真空炉 Z-16
export const VACUUM_FORMULA_INFO_Z6 = [
  {
    label: "阶段",
    key: "stageId",
    value: "",
    type: "",
    stageId: ""
  },
  {
    label: "升/降温速率",
    key: "oneExpandInfo",
    value: "",
    type: "input",
    oneExpandInfo: ""
  },
  {
    label: "保温设定值",
    key: "twoExpandInfo",
    value: "",
    type: "input",
    twoExpandInfo: ""
  },
  {
    label: "带宽",
    key: "threeExpandInfo",
    value: "",
    type: "input",
    threeExpandInfo: ""
  },
  {
    label: "小时/分钟设定值",
    key: "fourExpandInfo",
    value: "",
    type: "input",
    fourExpandInfo: ""
  },
  {
    label: "事件",
    key: "fiveExpandInfo",
    value: "",
    type: "input",
    fiveExpandInfo: ""
  },
  {
    label: "分压压力",
    key: "sixExpandInfo",
    value: "",
    type: "input",
    sixExpandInfo: ""
  },
  {
    label: "sevenExpandInfo",
    key: "sevenExpandInfo",
    value: "",
    type: "radio",
    sevenExpandInfo: "",
    hide: true
  },
  {
    label: "eightExpandInfo",
    key: "eightExpandInfo",
    value: "",
    type: "radio",
    eightExpandInfo: "",
    hide: true
  },
  {
    label: "nineExpandInfo",
    key: "nineExpandInfo",
    value: "",
    type: "radio",
    eightExpandInfo: "",
    hide: true
  },
  {
    label: "tenExpandInfo",
    key: "tenExpandInfo",
    value: "",
    type: "radio",
    eightExpandInfo: "",
    hide: true
  }
];

// 真空炉 Z-17
export const VACUUM_FORMULA_INFO_Z17 = [
  {
    label: "阶段",
    key: "stageId",
    value: "",
    type: "",
    stageId: ""
  },
  {
    label: "设定温度℃",
    key: "oneExpandInfo",
    value: "",
    type: "input",
    oneExpandInfo: ""
  },
  {
    label: "设定时间",
    key: "twoExpandInfo",
    value: "",
    type: "input",
    twoExpandInfo: ""
  },
  {
    label: "保证",
    key: "threeExpandInfo",
    value: "",
    type: "radio",
    threeExpandInfo: "",
    options: [
      {
        label: "是",
        value: "1"
      },
      {
        label: "否",
        value: "0"
      }
    ]
  },
  {
    label: "分压",
    key: "fourExpandInfo",
    value: "",
    type: "radio",
    fourExpandInfo: "",
    options: [
      {
        label: "开",
        value: "1"
      },
      {
        label: "关",
        value: "0"
      }
    ]
  },
  {
    label: "fiveExpandInfo",
    key: "fiveExpandInfo",
    value: "",
    type: "radio",
    fiveExpandInfo: "",
    hide: true
  },
  {
    label: "sixExpandInfo",
    key: "sixExpandInfo",
    value: "",
    type: "radio",
    sixExpandInfo: "",
    hide: true
  },
  {
    label: "sevenExpandInfo",
    key: "sevenExpandInfo",
    value: "",
    type: "radio",
    sevenExpandInfo: "",
    hide: true
  },
  {
    label: "eightExpandInfo",
    key: "eightExpandInfo",
    value: "",
    type: "radio",
    eightExpandInfo: "",
    hide: true
  },
  {
    label: "nineExpandInfo",
    key: "nineExpandInfo",
    value: "",
    type: "radio",
    eightExpandInfo: "",
    hide: true
  },
  {
    label: "tenExpandInfo",
    key: "tenExpandInfo",
    value: "",
    type: "radio",
    eightExpandInfo: "",
    hide: true
  }
];
// 真空炉 Z-12
export const VACUUM_FORMULA_INFO_Z2 = [
  {
    label: "阶段",
    key: "stageId",
    value: "",
    type: "",
    stageId: ""
  },
  {
    label: "设定温度℃",
    key: "oneExpandInfo",
    value: "",
    type: "input",
    oneExpandInfo: ""
  },
  {
    label: "设定时间",
    key: "twoExpandInfo",
    value: "",
    type: "input",
    twoExpandInfo: ""
  },
  {
    label: "分压",
    key: "threeExpandInfo",
    value: "",
    type: "radio",
    threeExpandInfo: "",
    options: [
      {
        label: "开",
        value: "1"
      },
      {
        label: "关",
        value: "0"
      }
    ]
  },
  {
    label: "真空冷",
    key: "fourExpandInfo",
    value: "",
    type: "radio",
    fourExpandInfo: "",
    options: [
      {
        label: "开",
        value: "1"
      },
      {
        label: "关",
        value: "0"
      }
    ]
  },
  {
    label: "静态冷",
    key: "fiveExpandInfo",
    value: "",
    type: "radio",
    fiveExpandInfo: "",
    options: [
      {
        label: "开",
        value: "1"
      },
      {
        label: "关",
        value: "0"
      }
    ]
  },
  {
    label: "风机冷",
    key: "sixExpandInfo",
    value: "",
    type: "radio",
    sixExpandInfo: "",
    options: [
      {
        label: "开",
        value: "1"
      },
      {
        label: "关",
        value: "0"
      }
    ]
  },
  {
    label: "工件偶保温",
    key: "sevenExpandInfo",
    value: "",
    type: "radio",
    sevenExpandInfo: "",
    options: [
      {
        label: "开",
        value: "1"
      },
      {
        label: "关",
        value: "0"
      }
    ]
  },
  {
    label: "2Bar正压",
    key: "eightExpandInfo",
    value: "",
    type: "radio",
    eightExpandInfo: "",
    options: [
      {
        label: "开",
        value: "1"
      },
      {
        label: "关",
        value: "0"
      }
    ]
  },
  {
    label: "nineExpandInfo",
    key: "nineExpandInfo",
    value: "",
    type: "radio",
    eightExpandInfo: "",
    hide: true
  },
  {
    label: "tenExpandInfo",
    key: "tenExpandInfo",
    value: "",
    type: "radio",
    eightExpandInfo: "",
    hide: true
  }
];
// 真空炉Z2的 图表展示字段
export const CHART_KEYS_Z2 = [
  {
    key: "meter1RealTemp",
    label: "PV"
  },
  {
    key: "furnceHighvacuum",
    label: "炉内高真空"
  },
  {
    key: "furnceLowvacuum",
    label: "炉内低真空"
  }
];
// 真空炉Z16的 图表展示字段
export const CHART_KEYS_PV = [
  {
    key: "meter1RealTemp",
    label: "PV1",
    yAxisIndex: 0
  },
  {
    key: "meter2RealTemp",
    label: "PV2",
    yAxisIndex: 0
  },
  {
    key: "meter3RealTemp",
    label: "PV3",
    yAxisIndex: 0
  }
];
export const CHART_KEYS_Z17 = [
  {
    key: "meter1RealTemp",
    label: "PV"
  },
  {
    key: "ionizationVacuumDegree",
    label: "电离真空度"
  },
  {
    key: "resistanceVacuumDegree",
    label: "电阻真空度"
  }
];

// 配方的校验字段

export const formulaRules = {
  // 温度上下限(℃)
  UP_TEMP: "温度上限(℃)",
  DOW_TEMP: "温度下限(℃)",
  UP_TIME: "保温时间上限(min)",
  DOW_TIME: "保温时间下限(min)",
  UP_HEAT_TIME: "热透时间上限(min)",
  DOW_HEAT_TIME: "热透时间下限(min)",
  DOW_HEAT_TIME_ZK: "加热时间下限(℃)",
  UP_HEAT_TIME_ZK: "加热时间上限(℃)"
};
